<?php
/*
*	Kleophatra - Open Source Content Management System
*	------------------------------------------------------------------------
*	Copyright (C) 2007-2009, Sergio Milardovich <smilardovich@yahoo.com.ar>
*	This program is Free Software.
*	Show posts
*
*	@package	Kleophatra
*	@subpackage	/modules/blog/widgets
*	@license	http://www.gnu.org/copyleft/gpl.html GNU/GPL License 2.0
*	@author		Sergio Milardovich <smilardovich@yahoo.com.ar>
*	@link		http://www.kleophatra.org
*/
	$output=null;
	$ref = $_SESSION['widget_ref']['blog->show'];

	$widget_form['blog->show'] =  array(
   		"Limit" => array("widget_get_blog_posts_limit","text"),
   		"Topic" => array("widget_get_blog_posts_topic", array("type" => "select", "options" => $this->get_topics_select(), "selected" => $this->get_core_value('widget_get_blog_posts_topic','name',$ref))),
   		"Order by" => array("widget_get_blog_posts_orderby", "text")
	);

	if($this->is_value("widget_get_blog_posts_limit",$ref)){
		$limit = $this->get_core_value("widget_get_blog_posts_limit", "name", $ref);
	} else {
		$limit = $this->add_core_value("widget_get_blog_posts_limit", 5, $ref);
	}
	if(!$this->is_value("widget_get_blog_posts_topic",$ref)){
		$this->add_core_value('widget_get_blog_posts_topic',0,$ref);
	}
	$topic = $this->get_core_value("widget_get_blog_posts_topic","name",$ref);

	if($topic == 0){
		unset($topic);
	}
	if(!$this->is_value("widget_get_blog_orderby",$ref)){
		$this->add_core_value('widget_get_blog_orderby','id DESC',$ref);
	}
	$orderby = $this->get_core_value("widget_get_blog_orderby","name",$ref);

	if(!$topic){
		$widget_query = $this->query("SELECT * FROM ".KLEO_TABLE_PREFIX."blog WHERE status = 1 AND type = 1 ORDER BY $orderby LIMIT $limit");
	} else {
		$widget_query = $this->query("SELECT * FROM ".KLEO_TABLE_PREFIX."blog, ".KLEO_TABLE_PREFIX."assoc WHERE status = 1 AND type = 1 AND assoctopic = $topic AND assoctype = 1 AND associtem = id ORDER BY $orderby LIMIT $limit");
	}
	$output .= '<ul>';
	/* Edit this if you want to customize the way that the posts are shown */
	while($wrow = $this->fetch_array($widget_query)){
		$output .= '<li><a href="index.php?module=blog&p='.$wrow['id'].'">'.$wrow['title'].'</a></li>';
	}
	$output .= '</ul>';

?>
